 #include "mapwidget.h"
#include "cells.h"
static uint32_t clear_gate = 1;
//static int map_zoom = 14;

//static int map_zoom = 17;
static int map_zoom = 15;

static dvec2 CenterLonLat = {108.918494, 34.233969};//中心坐标,学校
//static dvec2 CenterLonLat = {113.13,40.72};//中心坐标,阿拉善

//static dvec2 CenterLonLat = {105.6963888888888,38.8422222222222};//中心坐标,阿拉善宾馆   E105.41.47，N38.50.32


//static dvec2 CenterLonLat = {105.6963888888888,38.8422222222222};//中心坐标,阿拉善宾馆   E105.41.47，N38.50.32


//static dvec2 CenterLonLat = {105.6166666666666,38.7581481481481};//中心坐标,阿拉善测试基地   E105.37.0，N38.45.22    0616


//static dvec2 CenterLonLat = {105.61636883333334,38.806153750};//中心坐标,阿拉善测试基地   E105.37.0，N38.45.22    0620


static float MapRange = 15000;
static double  AXESRANGE = 20037508.3427892;
static float R = Aircraft::Aircraft_size_R;
static float r = R * Aircraft::GoldenRatio;
static float offset_x = r;
static float offset_y = r+sqrt((R+r)*(R+r)-R*R);
static int colorIndex = 0;
static float point_size = 0.4;
int point_clear =5;

MapWidget::MapWidget(QWidget *parent): QWidget(parent)
{
    scene = new GraphicsScene(this);
    view = new View("Map Display", this);
    view->view()->setScene(scene);
    mainlayout = new QHBoxLayout(this);
    mainlayout->addWidget(view);
    setWindowTitle(tr("Map Display"));

    //data initialize
    m_MapRange = MapRange;                                    //地图扩展距离
    m_zoom = map_zoom;                                        //地图级数
    m_RadarParam.PosLonLat = m_MapCenter_LonLat;              //雷达位置初始化
    memcpy(&m_MapCenter_LonLat, &CenterLonLat, sizeof(dvec2));//地图中心
    memcpy(&m_RadarParam.PosLonLat, &m_MapCenter_LonLat, sizeof(dvec2));
    m_RadarParam.fRadarDetectionDistance = 500;              //设定初始显示距离

    //m_RadarParam.fRadarDetectionDistance = 10000;//看航迹10km   256--2000,32---10000

    m_RadarParam.fDirectionAngle = 346.1;                     //设定初始显示法线方向
    m_RadarParam.fStartAngle = -45;
    m_RadarParam.fEndAngle = 45;
    m_RadarParam.fNorthOffset = 0.0f;
    m_scale = 1.0;

    m_resolutionintheZoom = 2.0*AXESRANGE/IMG_SIZE/pow(2, m_zoom);//分辨率
    m_Region = getRegionontheScene(m_MapCenter_LonLat, m_RadarParam.PosLonLat, m_zoom);//雷达中心

    colors[0] = QColor(91,  155, 213);
    colors[1] = QColor(236, 152,  68);
    colors[2] = QColor(229, 97,   75);
    colors[3] = QColor(146, 191, 113);
    colors[4] = QColor(225, 230,  49);
    colors[5] = QColor(106, 198, 180);
    colors[6] = QColor(125, 109, 195);
    colors[7] = QColor(206, 98,  162);
    colors[8] = QColor(135, 169, 150);
    colors[9] = QColor(64,  219, 240);

    //configuration widgets
    RadarParameterWidget = new RadarParamWidget(m_RadarParam);
    TrackSettingWidget = new TrackerController();
    setupMap(m_MapCenter_LonLat, m_MapRange);
    setupRadarParameter(m_RadarParam.PosLonLat, m_RadarParam.fRadarDetectionDistance, m_RadarParam.fDirectionAngle,
                        m_RadarParam.fStartAngle, m_RadarParam.fEndAngle, m_RadarParam.fNorthOffset);
    connect(this, SIGNAL(emittoPaintTracker()), this, SLOT(refreshTrackersSlot()));
    connect(this, SIGNAL(emittoPaintPoints()), this, SLOT(refreshPointsSlot()));
    connect(view, SIGNAL(emitscalechanged(float)), this, SLOT(getScale(float)));
    connect(view, SIGNAL(setRadarParameter()), RadarParameterWidget, SLOT(show()));
    connect(view, SIGNAL(setTrack()), TrackSettingWidget, SLOT(show()));
    connect(RadarParameterWidget, SIGNAL(emitRadarParameter(dvec2, float, float, float,float,float)), this, SLOT(RadarParameterChanged(dvec2,float,float,float,float, float)));
    connect(view, SIGNAL(clearMap()), this, SLOT(clearMap()));
    connect(view, SIGNAL(triggeredMonitorAreaSig()), scene, SLOT(getMonitorAreaFlag()));
    connect(view, SIGNAL(triggeredAlertAreaSig()),   scene, SLOT(getAlertAreaFlag()));
    connect(view, SIGNAL(triggeredAreaSignal(AreaType)), scene, SLOT(getAreaType(AreaType)));
    connect(scene, SIGNAL(AreaSelecting(QPointF,AreaType)), this, SLOT(AreaStlecting(QPointF,AreaType)));
    connect(scene, SIGNAL(AreaFinished(AreaType)), this, SLOT(AreaSelectionEnds(AreaType)));
}

MapWidget::~MapWidget()
{
    delete RadarParameterWidget;
    delete TrackSettingWidget;
}

int MapWidget::refresh_track(Targets_Info *data, int count)
{
    if(data==NULL || count<0)
        return -1;
    else
    {
        mutex_data.wait();
        //!删除掉上一圈消亡航迹的数据
        QMap<int, QVector<ItemAttribute_t*>>::iterator iter = Track_Data.begin();
        while(iter != Track_Data.end())
        {
            if(!iter.value().empty())
            {
                switch (iter.value().last()->state){
                case Expired_Tracker:
                {
                    for(QVector<ItemAttribute_t*>::iterator it = iter.value().begin();
                        it!=iter.value().end(); it++)//删除消亡航迹的每个元素
                    {
                        free(*it);//free data pointer
                        (*it) = NULL;
                    }
                    iter.value().clear();//clear vector
                    Track_Data.erase(iter++);//clear map
                    break;
                }
                case New_Tracker:
                {
                    iter.value().at(iter.value().size()-1)->state = Detective_Tracker;
                    iter++;
                    break;
                }
                case Active_Tracker:
                {
                    iter.value().at(iter.value().size()-1)->state = Detective_Tracker;
                    iter++;
                    break;
                }
                default:
                {
                    iter++;
                }
                }
            }
            else
            {
                qDebug() << "(1)Track_Data.value at this key is empty! in Function refresh_track()";
                Track_Data.erase(iter++);//清理map
            }
        }

        //!更新需要更新的航迹和新航迹
        int key = 0;
        for(int i=0; i<count; i++)
        {
            key = data->target[i].BatchID;
            iter = Track_Data.find(key);
            ItemAttribute_t *tmp = (ItemAttribute_t*)malloc(sizeof(ItemAttribute_t));
            tmp->frameID = data->frame;
            tmp->Track_Range = data->target[i].Distance;
            tmp->Track_Azimuth = data->target[i].Angle;
            tmp->Track_Velocity = data->target[i].Speed;

            //!找到航迹
            if(iter!=Track_Data.end())//found
            {
                tmp->state = Active_Tracker;//active
                iter->append(tmp);
            }
            else//!未找到航迹
            {
                tmp->state = New_Tracker;//new
                QVector<ItemAttribute_t*> vec;
                vec.append(tmp);
                Track_Data.insert(key, vec);
            }

        }


        //!找到新的要删除的航迹
        iter = Track_Data.begin();
        while(iter!=Track_Data.end())
        {
            if(!iter.value().empty())
            {
                if(abs(data->frame-iter.value().last()->frameID)>clear_gate)
                    iter.value().at(iter.value().size()-1)->state = Expired_Tracker;
                iter++;
            }
            else{
                qDebug() << "(2)Track_Data.value at this key is empty! in Function refresh_track()";
                Track_Data.erase(iter++);
            }
        }
        mutex_data.signal();
        emittoPaintTracker();
        return 0;
    }
}

int MapWidget::refresh_target(Targets_Info *points, int count)
{
    if(points!=NULL && count>0)
    {
        mutex_point.wait();

        ItemAttribute_t elem_topush;
        QVector<ItemAttribute_t>::iterator iter = point_Data.begin();
        while(iter!=point_Data.end())
        {
            if(points->frame-iter->frameID >= point_clear)
            {
                iter->state = ExpiredPoint;
                iter++;
            }
            else
                break;
        }
        for(int i=0; i<count; i++)
        {
            elem_topush.frameID = points->frame;
            elem_topush.targetID = points->target[i].BatchID;
            elem_topush.Track_Azimuth = points->target[i].Angle + m_RadarParam.fNorthOffset /*+ m_RadarParam.fDirectionAngle*/;
            elem_topush.Track_Range = points->target[i].Distance;
            elem_topush.Track_Velocity = points->target[i].Speed;
            elem_topush.state = Point;
            point_Data.append(elem_topush);
        }
        mutex_point.signal();
        emittoPaintPoints();
    }
    else
    {
        qDebug() << "input error in Func():refresh_target";
    }
}

void MapWidget::setupMap(dvec2 LonLat, float distance)
{
    memcpy(&m_MapCenter_LonLat, &LonLat, sizeof(dvec2));
    m_MapRange = distance;
    ulvec2 centerTile = transferLonLattoTileMap_rtn_uint64_t(LonLat, m_zoom);  //计算中心瓦片位置
    int MapOffset = calcNeededTilesNumbers(distance, m_zoom);               //计算所需的瓦片数

    for (int i = -(MapOffset); i < MapOffset; i += 1) {
        for (int j = -MapOffset; j < MapOffset; j += 1) {
            QGraphicsItem *item = new MapTile(centerTile.x + i, centerTile.y + j, m_zoom);
            item->setPos(QPointF(i*IMG_SIZE, j*IMG_SIZE));
            scene->addItem(item);
        }
    }
}

void MapWidget::setupRadarParameter(dvec2 Location, float DetectionDistance, float DirectionAngle, float StartAngle, float EndAngle, float northOffset)
{
    memcpy(&m_RadarParam.PosLonLat, &Location, sizeof(dvec2));
    m_RadarParam.fRadarDetectionDistance = DetectionDistance;
    m_RadarParam.fDirectionAngle = DirectionAngle;
    m_RadarParam.fStartAngle = StartAngle;
    m_RadarParam.fEndAngle = EndAngle;
    m_RadarParam.fNorthOffset = northOffset;

    m_Region = getRegionontheScene(m_MapCenter_LonLat, m_RadarParam.PosLonLat, m_zoom);//雷达中心
    QGraphicsItem *item = new LocationIcon(m_RadarParam.fRadarDetectionDistance/m_resolutionintheZoom, m_RadarParam.fDirectionAngle + m_RadarParam.fNorthOffset, m_RadarParam.fStartAngle, m_RadarParam.fEndAngle);
    item->setPos(QPointF(m_Region.x - (134.0 / 512.0) * LOCATION_ICON_SIZE,
                         m_Region.y - (478.0 / 512.0) * LOCATION_ICON_SIZE));
    scene->addItem(item);
    scene->update();
}

void MapWidget::refreshTrackersSlot()
{
    mutex_data.wait();
    mutex_path.wait();
    int key_path;
    QMap<int, Tracker*>::iterator iter_path = Track_Path.begin();
    QMap<int, QVector<ItemAttribute_t*>>::iterator iter_data = Track_Data.begin();

    while(iter_data != Track_Data.end())//data
    {
        key_path = iter_data.key();
        iter_path = Track_Path.find(key_path);
        if(iter_path!=Track_Path.end()){
            if(!iter_data.value().isEmpty()){
                switch(iter_data.value().last()->state){
                case Active_Tracker:
                {
                    dvec2 lineto_pos = getPositionontheScene(iter_data.value().last()->Track_Range, iter_data.value().last()->Track_Azimuth);
#if 0
                    AircraftParam params = {iter_data.value().last()->Track_Range,
                                           iter_data.value().last()->Track_Azimuth,
                                           iter_data.value().last()->Track_Velocity};
#else

                    AircraftParam params = {iter_data.value().last()->Track_Range,
                                           iter_data.value().last()->Track_Azimuth/*+m_RadarParam.fDirectionAngle*/,
                                           iter_data.value().last()->Track_Velocity};
#endif
                    QPointF lineto_point(lineto_pos.x, lineto_pos.y);//scene position
                    bool isInMonitor = false;
                    for(int i=0; i<MonitorAreaVec.size(); i++)
                    {
                        isInMonitor = isPointinPolygon(lineto_point, MonitorAreaVec.at(i));
                        if(isInMonitor)
                        {
                            break;
                        }
                    }
                    bool isInAlert = false;
                    for(int i=0; i<AlertAreaVec.size(); i++)
                    {
                        isInAlert = isPointinPolygon(lineto_point, AlertAreaVec.at(i));
                        if(isInAlert)
                        {
                            break;
                        }
                    }

                    if(isInAlert)
                    {
                        if(!Track_Path[key_path]->isColored()){
                            Track_Path[key_path]->setTrackerColor(colors[colorIndex%10]);
                            colorIndex++;
                            QMessageBox::warning(this, tr("警告!"),
                                                 tr("航迹编号：")+QString::number(key_path),
                                                 QMessageBox::Ok, QMessageBox::Ok);
                        }
                        Track_Path[key_path]->setAreaType(AlertArea);
                    }
                    else if(isInMonitor)
                    {
                        if(!Track_Path[key_path]->isColored()){
                            Track_Path[key_path]->setTrackerColor(colors[colorIndex%10]);
                            colorIndex++;
                        }
                        Track_Path[key_path]->setAreaType(MonitorArea);
                    }
                    else
                    {
                        Track_Path[key_path]->setAreaType(Others);
                    }

                    Track_Path[key_path]->icon->setPositionInfo(params);
                    Track_Path[key_path]->Lineto(QPointF(lineto_pos.x, lineto_pos.y));
                    Track_Path[key_path]->icon->setPos(lineto_pos.x-Track_Path[key_path]->pos().x()- offset_x/m_scale,
                                                       lineto_pos.y-Track_Path[key_path]->pos().y()- offset_y/m_scale);
                    Track_Path[key_path]->icon->setScale(1/m_scale);
                    break;
                }
                case Expired_Tracker:
                {
                    scene->removeItem(iter_path.value());//场景移除
                    delete iter_path.value();            //delete
                    Track_Path.erase(iter_path++);       //map移除
                    break;
                }
                default:
                    break;
                }
            }
            else
            {
                qDebug() << "(1)Tracker_Data_map at this key is empty in Function(drawTracker_painting)";
            }
        }
        else
        {
            if(!iter_data.value().isEmpty())
            {
                dvec2 start_pos = getPositionontheScene((Track_Data[key_path]).last()->Track_Range, (Track_Data[key_path]).last()->Track_Azimuth);
                Tracker *path = new Tracker(key_path, QPointF(start_pos.x, start_pos.y));
                path->setPos(start_pos.x, start_pos.y);
                path->icon->setPos(-offset_x/m_scale, -offset_y/m_scale);
                path->icon->setScale(1/m_scale);
                scene->addItem(path);
                Track_Path.insert(key_path, path);
            }
            else
            {
                qDebug() << "(2)Tracker_Data_map at this key is empty in Function(drawTracker_painting)";
            }
        }
        iter_data++;
    }
    mutex_path.signal();
    mutex_data.signal();
}

void MapWidget::refreshPointsSlot()
{
    mutex_point.wait();
    for(int i=0; i<point_Data.size();)
    {
        if(point_Data.at(i).state == ExpiredPoint)
        {
            point_Data.erase(point_Data.begin());
            if(!point_list.empty()){
                scene->removeItem(point_list.at(0));
                point_list.erase(point_list.begin());
            }
        }
        else
            break;
    }
    int frame = 0;
    if(!point_Data.empty())
    {
        frame = point_Data.last().frameID;
        for(int i=0; i<point_Data.size(); i++)
        {
            if(point_Data.at(i).frameID==frame)
            {
                dvec2 pos = getPositionontheScene(point_Data.at(i).Track_Range, point_Data.at(i).Track_Azimuth);
                pos.x = m_Region.x + point_Data.at(i).Track_Range / m_resolutionintheZoom * cos((90.0 - point_Data.at(i).Track_Azimuth ) *2.0 *pi/360.0);
                pos.y = m_Region.y - point_Data.at(i).Track_Range / m_resolutionintheZoom * sin((90.0 - point_Data.at(i).Track_Azimuth ) *2.0 *pi/360.0);
                QGraphicsEllipseItem* point = new QGraphicsEllipseItem(QRectF(pos.x, pos.y, 6, 6));
                QPen pen = point->pen();
                pen.setWidth(0.8);
                pen.setColor(Qt::white);
                point->setPen(pen);
                point->setBrush(QBrush(QColor(255, 0, 0, 150)));
                scene->addItem(point);
                point_list.append(point);
            }
        }


    }
    mutex_point.signal();
}

void MapWidget::getScale(float scale)
{
    mutex_path.wait();
    for(QMap<int, Tracker*>::iterator iter_path = Track_Path.begin();
        iter_path!=Track_Path.end(); iter_path++)
    {
        iter_path.value()->icon->moveBy(offset_x/m_scale, offset_y/m_scale);
        iter_path.value()->icon->setScale(1/scale);
        iter_path.value()->icon->moveBy(-offset_x/scale, -offset_y/scale);
    }
    m_scale = scale;
    scene->update();
    mutex_path.signal();
}

void MapWidget::clearBuffer()
{
    mutex_data.wait();
    QMap<int, QVector<ItemAttribute_t*>>::iterator iter_data = Track_Data.begin();
    while(iter_data!=Track_Data.end()){
        QVector<ItemAttribute_t*>::iterator iter_vec = iter_data.value().begin();
        while(iter_vec!=iter_data.value().end()){
            free(*iter_vec);
            (*iter_vec) = NULL;
            iter_vec++;
        }
        iter_data.value().clear();
        iter_data++;
    }
    Track_Data.clear();
    mutex_data.signal();
    mutex_path.wait();
    Track_Path.clear();
    mutex_path.signal();

}

void MapWidget::clearItemsExceptMap()
{
    QList<QGraphicsItem*> list = scene->items();
    for(int i=0; i<list.size(); i++)
    {
        if(list.at(i)->type() != MapTile::Type)
            scene->removeItem(list.at(i));
    }
    list.clear();
}

void MapWidget::clearTrackerItems()
{
    QList<QGraphicsItem*> list = scene->items();
    for(int i=0; i<list.size(); i++)
    {
        if(list.at(i)->type()!=MapTile::Type && list.at(i)->type()!=LocationIcon::Type)
            scene->removeItem(list.at(i));
    }
    list.clear();
}

bool MapWidget::isPointinPolygon(QPointF testPoint, QVector<QPointF> polygon)
{
      bool isIn = false;
      for(int i = 0,j= polygon.size()-1; i < polygon.size(); j = i++)
      {
        if ( ((polygon.at(i).y()>testPoint.y())!=(polygon.at(j).y()>testPoint.y())) &&
           (testPoint.x()<(polygon.at(j).x()-polygon.at(i).x())*(testPoint.y()-polygon.at(i).y())/(polygon.at(j).y()-polygon.at(i).y())+polygon.at(i).x()))
           isIn = !isIn;
      }
      return isIn;

}

void MapWidget::AreaStlectionStarts(QPointF pos, AreaType type)
{

}

void MapWidget::AreaStlecting(QPointF pos, AreaType type)
{
    switch (type) {
    case MonitorArea:
    {
        if(AreaData.empty())
        {
            PolygonAreaItem *MonitorAreaItem = new PolygonAreaItem(0, pos, MonitorArea);
            MonitorItems.push_back(MonitorAreaItem);
            scene->addItem(MonitorAreaItem);
            AreaData.push_back(pos);
        }
        else
        {
            AreaData.push_back(pos);
            MonitorItems.last()->Lineto(pos);
        }
        break;
    }
    case AlertArea:
    {
        if(AreaData.empty())
        {
            PolygonAreaItem *AlertAreaItem = new PolygonAreaItem(0, pos, AlertArea);
            AlertItems.push_back(AlertAreaItem);
            scene->addItem(AlertAreaItem);
            AreaData.push_back(pos);
        }
        else
        {
            AreaData.push_back(pos);
            AlertItems.last()->Lineto(pos);
        }
        break;
    }
    default:
        break;
    }
}

void MapWidget::AreaSelectionEnds(AreaType type)
{
    switch (type) {
    case MonitorArea:
    {
        MonitorItems.last()->PolygonFinished();
        if(AreaData.size()>2)
        {
            QVector<QPointF> mav(AreaData);
            MonitorAreaVec.push_back(mav);
        }
        AreaData.clear();
        break;
    }

    case AlertArea:
    {
        AlertItems.last()->PolygonFinished();
        if(AreaData.size()>2)
        {
            QVector<QPointF> aav(AreaData);
            AlertAreaVec.push_back(aav);
        }
        AreaData.clear();
        break;
    }
    default:
        break;
    }
}

void MapWidget::clearMap()
{
    clearBuffer();
    clearTrackerItems();
}

void MapWidget::RadarParameterChanged(dvec2 Location, float DetectionDistance, float DirectionAngle, float StartAngle, float EndAngle, float northOffset)
{
    clearBuffer();
    clearItemsExceptMap();
    m_Region = getRegionontheScene(m_MapCenter_LonLat, Location, m_zoom);//雷达中心
    setupRadarParameter(Location, DetectionDistance, DirectionAngle, StartAngle, EndAngle, northOffset);
}

dvec2 MapWidget::transferLonLattoTileMap_rtn_double(dvec2 LonLat, uint32_t zoom)
{
    dvec2  mercator;
    dvec2 TileCoordinate;
    double TilesCount = pow(2, zoom);
    mercator.x = LonLat.x *AXESRANGE/180;
    mercator.y= log(tan((90.0+LonLat.y)*pi/360))/pi*180.0;
    mercator.y = mercator.y *AXESRANGE/180;
    TileCoordinate.x = AXESRANGE + mercator.x;
    TileCoordinate.y = AXESRANGE - mercator.y;
    TileCoordinate.x = TileCoordinate.x/2.0/AXESRANGE*TilesCount;
    TileCoordinate.y = TileCoordinate.y/2.0/AXESRANGE*TilesCount;
    return TileCoordinate;
}

ulvec2 MapWidget::transferLonLattoTileMap_rtn_uint64_t(dvec2 LonLat, uint32_t zoom)
{
    dvec2  mercator;
    ulvec2 TileCoordinate;
    double TilesCount = pow(2, zoom);
    mercator.x = (LonLat.x * AXESRANGE) / 180;
    mercator.y= log(tan((90 + LonLat.y) * pi / 360))/(pi / 180);
    mercator.y = (mercator.y * AXESRANGE)/180;
    TileCoordinate.x = AXESRANGE + mercator.x;
    TileCoordinate.y = AXESRANGE - mercator.y;
    TileCoordinate.x = (uint64_t)(TileCoordinate.x/2.0/AXESRANGE*TilesCount);
    TileCoordinate.y = (uint64_t)(TileCoordinate.y/2.0/AXESRANGE*TilesCount);
    return TileCoordinate;
}

int MapWidget::calcNeededTilesNumbers(float ExtendedDistance, uint32_t zoom)
{
    m_zoom = zoom;
    return ceil(ExtendedDistance * 1.0 /m_resolutionintheZoom/IMG_SIZE) ;
}

dvec2 MapWidget::getRegionontheScene(dvec2 MapCentralPos, dvec2 RadarCentralPos, uint32_t zoom)
{
    dvec2 centralTilePos_Map = transferLonLattoTileMap_rtn_double(MapCentralPos, zoom);
    dvec2 RadarCentralPos_Radar = transferLonLattoTileMap_rtn_double(RadarCentralPos, zoom);
    RadarCentralPos_Radar.x = (RadarCentralPos_Radar.x- (uint64_t)centralTilePos_Map.x)*IMG_SIZE;
    RadarCentralPos_Radar.y = (RadarCentralPos_Radar.y- (uint64_t)centralTilePos_Map.y)*IMG_SIZE;
    return RadarCentralPos_Radar;
}

dvec2 MapWidget::getPositionontheScene(float distance, float angle)
{
    dvec2 posf;
#if 1
    posf.x = m_Region.x + distance / m_resolutionintheZoom * cos((90.0 - angle /*- m_RadarParam.fDirectionAngle*/) *2.0 *pi/360.0);
    posf.y = m_Region.y - distance / m_resolutionintheZoom * sin((90.0 - angle  /*- m_RadarParam.fDirectionAngle*/) *2.0 *pi/360.0);
#else
    posf.x = m_Region.x + distance / m_resolutionintheZoom * cos((90.0 - angle - m_RadarParam.fNorthOffset) *2.0 *pi/360.0);
    posf.y = m_Region.y - distance / m_resolutionintheZoom * sin((90.0 - angle - m_RadarParam.fNorthOffset) *2.0 *pi/360.0);
#endif
    return posf;
}
